/*
	Personal Bug Tracker (www.personalbugtracker.com)
	Copyright (C) 2014 Sergey Nechaev <serg.nechaev@gmail.com>

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
package com.personalbugtracker.ui.controller;

import java.net.URL;
import java.util.Date;
import java.util.ResourceBundle;

import com.personalbugtracker.PersonalBugTracker;
import com.personalbugtracker.domain.Project;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;

public class EditProjectFXController {

	@FXML
	// ResourceBundle that was given to the FXMLLoader
	private ResourceBundle resources;

	@FXML
	// URL location of the FXML file that was given to the FXMLLoader
	private URL location;

	@FXML
	// fx:id="tf_desc"
	private TextArea tf_desc; // Value injected by FXMLLoader

	@FXML
	// fx:id="lbl_cancel"
	private Button lbl_cancel; // Value injected by FXMLLoader

	@FXML
	// fx:id="tf_name"
	private TextField tf_name; // Value injected by FXMLLoader

	@FXML
	// fx:id="tf_id"
	private TextField tf_id; // Value injected by FXMLLoader

	@FXML
	// fx:id="lbl_save"
	private Button lbl_save; // Value injected by FXMLLoader

	@FXML
	void onSaveProject(ActionEvent event) {
		Project p = new Project();
		p.setDate(new Date());
		p.setDescription(this.tf_desc.getText());
		p.setIdentifier(this.tf_id.getText());
		p.setName(this.tf_name.getText());
		PersonalBugTracker.services.getProjectService().save(p);
		PersonalBugTracker.reloadProjectsTree();
		
	}

	@FXML
	// This method is called by the FXMLLoader when initialization is complete
	void initialize() {
		assert tf_desc != null : "fx:id=\"tf_desc\" was not injected: check your FXML file 'edit-project.fxml'.";
		assert lbl_cancel != null : "fx:id=\"lbl_cancel\" was not injected: check your FXML file 'edit-project.fxml'.";
		assert tf_name != null : "fx:id=\"tf_name\" was not injected: check your FXML file 'edit-project.fxml'.";
		assert tf_id != null : "fx:id=\"tf_id\" was not injected: check your FXML file 'edit-project.fxml'.";
		assert lbl_save != null : "fx:id=\"lbl_save\" was not injected: check your FXML file 'edit-project.fxml'.";

	}
}
